<template>
  <!-- 请假弹窗 -->
  <el-dialog
    class="leave_dialog"
    title="请假申请"
    :visible.sync="isOpen"
    :before-close="handleClose"
    :inline="true"
    center
  >
    <el-form ref="form" :model="formData" label-width="80px">
      <el-form-item label="请假类型">
        <el-select v-model="formData.type" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="请假时间">
        <el-date-picker
          v-model="formData.day"
          type="date"
          placeholder="选择日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="请假内容">
        <el-input
          type="textarea"
          v-model="formData.context"
          :rows="5"
          maxlength="200"
          show-word-limit
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="handleClose">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { getEventTypeApi, submitLeaveDataApi } from "@/api/new/index.js";
export default {
  name: "LeaveDialog",

  props: {
    isOpen: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      dialogVisible: this.isOpen,
      formData: {
        type: "",
        day: "",
        context: "",
      },
      options: [
        {
          label: "事假",
          value: "sj",
        },
        {
          label: "病假",
          value: "bj",
        },
      ],
    };
  },
  mounted() {
    this.getEventType();
  },
  methods: {
    /** 获取请假类型 */
    async getEventType() {
      // const res = await getEventTypeApi()
      // if(res) {
      //   this.options = res
      // }
    },
    handleClose() {
      this.$emit("closeDialog");
    },
    async submit() {
      this.$message({
        message: "提交成功",
        type: "success",
      });
      this.handleClose();

      // TODO：后端联调
      // try {
      //   let res = await submitLeaveDataApi(formData);
      //   if (res) {
      //     this.handleClose();
      //   }
      // } catch {
      //   this.$message({
      //     message: "提交失败",
      //     type: "warning",
      //   });
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
.leave_dialog {
}
</style>
